#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<memory>

using namespace std;
#include"shared_ptr.h"
template<class T>
class smart_ptr
{
public:
	smart_ptr( T* ptr)
		:_ptr(ptr)
	{

	}
	~smart_ptr()
	{
		cout << "~smart_ptr";
		delete _ptr;
		
	}
	T& operator*()
	{
		return *_ptr;
	}
	T& operator->()
	{
		return _ptr;
	}
private:
	T* _ptr;
};
struct Date
{
	int _year;
	int _month;
	int _day;
	Date(int year = 1, int month = 1, int day = 1)
		:_year(year)
		, _month(month)
		, _day(day)
	{
	}
	~Date()
	{
		cout << "~Date()" << endl;

	}
};
template<class T>
class DeleteArray
{
public:
	void operator()(T* ptr)
	{
		cout << "1";
		delete[] ptr;
	}
};
class Fclose
{
public:
	void operator()(FILE* ptr)
	{
		cout << "fclose:" << ptr << endl;
		fclose(ptr);
	}
};
int main()
{
	smart_ptr<int> sp1(new int(1));
	*sp1 = 2;
	cout << *sp1 << endl;
	auto_ptr<int>  sp3(new int(2));
	auto_ptr<Date> sp4(new Date(2222, 2, 2));
	//auto_ptr<Date> sp5(sp4);
	//sp4->_day++;
	unique_ptr<Date> sp6(new Date(1, 2, 3));
	unique_ptr<Date> sp7(move(sp4));
	unique_ptr<Date[]> sp8(new Date[10]);
	shared_ptr<Date[]> sp9(new Date[10]);
	unique_ptr<Date, DeleteArray<Date>> sp10(new Date[10]);
	shared_ptr<Date>sp11(new Date[10], DeleteArray<Date>());
	auto it = [](Date* ptr) {delete[] ptr; };
	unique_ptr<Date, decltype(it)> sp12(new Date[10], it);
	shared_ptr<Date> sp13(new Date[10], it);
	mutou::shared_ptr<Date> sp14(new Date[10],DeleteArray<Date>());
	mutou::shared_ptr<Date> sp15(sp14);
	return 0;
}